package com.czx.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czx.entity.Message;
import com.czx.entity.MyPage;
import com.czx.mapper.LetterMapper;
import com.czx.service.LetterService;
import com.czx.service.SysMessageService;
import com.czx.vo.LetterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LetterServiceImpl extends ServiceImpl<LetterMapper,Message> implements LetterService {
    @Autowired
    private LetterMapper letterMapper;


    @Override
    public MyPage getLetter(MyPage page, Integer id) {
      MyPage myPage= baseMapper.getLetter(page,id);
        List<LetterVo> records = myPage.getRecords();
        for (LetterVo record : records) {
            Integer unreadCount = baseMapper.getUnreadCount(record.getUser().getId(), id);
            record.setUnreadCount(unreadCount);
        }
        return myPage;
    }

    /**
     * 所有未读私信
     * @param id
     * @return
     */

    @Override
    public Integer secMessage(Integer id) {
        Integer integer = baseMapper.secMessage(id);
        return integer;
    }

    /**
     * 查询私信详情
     * @param page
     * @param fromId
     * @param toId
     * @return
     */
    @Override
    public MyPage getLetterList(MyPage page, Integer fromId, Integer toId) {
        MyPage letterList = baseMapper.getLetterList(page, fromId, toId);
        return letterList;
    }




}
